package com.hee.erp.modules.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hee.erp.modules.entity.CarCheck;
import com.hee.erp.modules.entity.CarInsure;
import com.hee.erp.modules.mapper.CarCheckMapper;
import com.hee.erp.modules.service.ICarCheckService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author weizehong
 * @since 2022-05-02
 */
@Service
@Transactional
public class CarCheckServiceImpl extends ServiceImpl<CarCheckMapper, CarCheck> implements ICarCheckService {

    @Override
    public List<CarCheck> listByCarId(String carId) {

        LambdaQueryWrapper<CarCheck> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CarCheck::getCarId, carId);
        wrapper.orderByDesc(CarCheck::getYears);
        List<CarCheck> list = list(wrapper);

        if(list.size() == 0){
            CarCheck item = new CarCheck();
            item.setYears(LocalDate.now().getYear() + "年");

            list.add(item);
        }
        return list;
    }
}
